package com.ktgj.sms.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.sms.domain.SMSInfo;
import com.ktgj.sms.domain.vo.SmsContentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.sms.domain.SmsAirlineticket;
import com.ktgj.sms.service.ISmsAirlineticketService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2022-08-04
 */
@RestController
@RequestMapping("/airlineticket")
public class SmsAirlineticketController extends BaseController
{
    @Autowired
    private ISmsAirlineticketService smsAirlineticketService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "system:airlineticket:list")
    @GetMapping("/list")
    public TableDataInfo list(SmsAirlineticket smsAirlineticket)
    {
        startPage();
        List<SmsAirlineticket> list = smsAirlineticketService.selectSmsAirlineticketList(smsAirlineticket);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "system:airlineticket:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsAirlineticket smsAirlineticket) throws IOException
    {
        List<SmsAirlineticket> list = smsAirlineticketService.selectSmsAirlineticketList(smsAirlineticket);
        ExcelUtil<SmsAirlineticket> util = new ExcelUtil<SmsAirlineticket>(SmsAirlineticket.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize(hasPermi = "system:airlineticket:query")
    @GetMapping(value = "/{keyId}")
    public AjaxResult getInfo(@PathVariable("keyId") Long keyId)
    {
        return AjaxResult.success(smsAirlineticketService.selectSmsAirlineticketById(keyId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "system:airlineticket:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsAirlineticket smsAirlineticket)
    {
        return toAjax(smsAirlineticketService.insertSmsAirlineticket(smsAirlineticket));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "system:airlineticket:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsAirlineticket smsAirlineticket)
    {
        return toAjax(smsAirlineticketService.updateSmsAirlineticket(smsAirlineticket));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "system:airlineticket:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{keyIds}")
    public AjaxResult remove(@PathVariable Long[] keyIds)
    {
        return toAjax(smsAirlineticketService.deleteSmsAirlineticketByIds(keyIds));
    }

    /**
     * 短信猫
     * */
    @PostMapping("/smsCat")
    public AjaxResult smsCat(@RequestBody SMSInfo smsInfo){
        int i;
        try {
            i = smsAirlineticketService.smsCat(smsInfo);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

        if (i > 0){
            return AjaxResult.success("添加成功");
        }
        else {
            return AjaxResult.error("添加失败");
        }
    }

    /**
     * 短信内容查询
     * */
    @PostMapping("/smsContent")
    public TableDataInfo smsContent(@RequestBody SmsContentVo smsContentVo){
        startPage();
        List<SmsAirlineticket> smsAirlineticket = smsAirlineticketService.smsContent(smsContentVo);
        return getDataTable(smsAirlineticket);
    }

    /**
     * 短信内容详情
     * */
    @PostMapping("/smsContentDetails")
    public AjaxResult smsContentDetails(HttpServletRequest request, @RequestBody Map<String, Object> map){
        Long id = Long.valueOf(map.get("id").toString());
        SmsAirlineticket smsAirlineticket;
        try {
            smsAirlineticket = smsAirlineticketService.smsContentDetails(request, id);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

        return AjaxResult.success(smsAirlineticket);
    }

    /**
     * 短信内容处理
     * */
    @PostMapping("/smsContentAudit")
    public AjaxResult smsContentAudit(@RequestBody SmsAirlineticket smsAirlineticket){
        int  i = smsAirlineticketService.smsContentAudit(smsAirlineticket);
        if (i > 0){
            return AjaxResult.success("处理成功");
        }
        else {
            return AjaxResult.error("处理失败");
        }
    }
}